﻿@model Admin.Models.ViewModel
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="widget">
                <div class="widget-head">
                    <div class="pull-left">
                        Versions</div>
                    <div class="widget-icons pull-right">
                        <a href="#" class="wminimize"><i class="icon-chevron-up"></i></a><a href="#" class="wclose">
                            <i class="icon-remove"></i></a>
                    </div>
                    <div class="clearfix">
                    </div>
                </div>
                <div class="widget-content" style="display: block;">
                    <div class="padd statement">
                        <div class="row">
                            <div class="col-md-3">
                                <div class="well">
                                    <h2>
                                        @Model.Versions.Count Versions</h2>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="well">
                                    <h2>
                                        @{
                                            var pageCount = Model.Versions.Sum(p => { return p.Pages == null ? 0 : p.Pages.Count; });
                                        }
                                        @pageCount Pages</h2>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="well">
                                    <h2>
                                        @{
                                            int pluginCount = Model.Versions.Sum(p => { return p.Pages == null ? 0 : p.Pages.Sum(q => q.Plugins.Count); });
                                            //add global plugins
                                            
                                        }
                                        @(pluginCount)
                                        Plugins</h2>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="well">
                                    <h2>
                                        @{
                                    //int fileIncludes = Model.Versions.Sum(p => p.FileIncludes.Count);
                                    //add page file includes
                                        }
                                        0 Files</h2>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <hr>
                                @if (Model.Versions.Count > 0)
                                {
                                    <table class="table table-striped table-hover table-responsive table-bordered">
                                        <thead>
                                            <tr>
                                                <th>
                                                    #
                                                </th>
                                                <th>
                                                    Name
                                                </th>
                                                <th>
                                                    Version ID
                                                </th>
                                                <th>
                                                    Version HTML
                                                </th>
                                                <th>
                                                    Created Date
                                                </th>
                                                <th>
                                                    Modified Date
                                                </th>
                                                <th>
                                                    Global Plugin #
                                                </th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @for (int i = 0; i < Model.Versions.Count; i++)
                                            {
                                                <tr class="@(Model.Versions[i].IsDefault ? "danger" : "")">
                                                    <td>
                                                        @(i + 1)
                                                    </td>
                                                    <td>
                                                        @Html.ActionLink(Model.Versions[i].VersionName, "detail", "version", new { vid = Model.Versions[i].VersionID, cid = Model.Company.CID }, null)
                                                    </td>
                                                    <td>
                                                        @Model.Versions[i].VersionID
                                                    </td>
                                                    <td>
                                                        @Model.Versions[i].VersionHTML
                                                    </td>
                                                    <td>
                                                        @Model.Versions[i].CreatedDate
                                                    </td>
                                                    <td>
                                                        @Model.Versions[i].ModifiedDate
                                                    </td>
                                                    <td>
                                                        @(Model.Versions[i].GlobalPlugins != null ? Model.Versions[i].GlobalPlugins.Count : 0)
                                                    </td>
                                                </tr>
                                            }
                                        </tbody>
                                    </table>
                                }
                            </div>
                        </div>
                    </div>
                    <div class="widget-foot">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="createversion" class="modal fade in" tabindex="-1" role="dialog" aria-labelledby="createversionLabel"
    aria-hidden="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    ×</button>
                <h4 class="modal-title">
                    Create Version</h4>
            </div>
            <div class="modal-body">
                <div class="matter">
                    <div class="container">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="form-horizontal" data-control="CreateVersion">
                                    <div class="form-group">
                                        <label class="col-lg-4 control-label">
                                            Name</label>
                                        <div class="col-lg-8">
                                            <input type="text" data-name="VersionName" class="form-control" placeholder="Version Name">
                                            <input type="hidden" data-name="VersionID" value="@Model.Versions.Max(P => P.VersionID)" />
                                            <input type="hidden" data-name="_id" value="@MongoDB.Bson.ObjectId.GenerateNewId().ToString()" />
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-4 control-label">
                                            Is Default</label>
                                        <div class="col-lg-8">
                                            <input data-type="toggle-switch-master" type="checkbox" data-name="IsDefault">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-lg-4 control-label">
                                            Master Page Html</label>
                                        <div class="col-lg-8">
                                            <textarea data-name="VersionHTML" class="form-control" placeholder="Master HTML with tokens"></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal" aria-hidden="true">
                    Close</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" data-action="CreateVersion">
                    Save changes</button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var version = JSON.parse('@Html.Raw(Model.VersionJson)');
</script>
